using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Lime49.UI;

namespace LockCrypt {
    /// <summary>
    /// A generic dialog which allows selection of a window from those which are open.
    /// </summary>
    public partial class WinChooseWindow : Window {
        //public static readonly DependencyProperty SelectedWindowProperty = DependencyProperty.Register("SelectedWindow", typeof(string), typeof(WinChooseWindow), new PropertyMetadata(string.Empty));
        /// <summary>
        /// Gets or sets the name of the selected window.
        /// </summary>
        /// <value>The selected window name.</value>
        public string SelectedWindow {
          //  get { return Convert.ToString(base.GetValue(SelectedWindowProperty)); }
            //set { base.SetValue(SelectedWindowProperty, value); }
            get { return windowChooser.SelectedWindow; }
            set { windowChooser.SelectedWindow = value; }
        }

        /// <summary>
        /// Initializes a new <see cref="WinChooseWindow"/>.
        /// </summary>
        public WinChooseWindow() {
            InitializeComponent();
        }

        /// <summary>
        /// Initializes a new <see cref="WinChooseWindow"/> to allow selection from a range of windows.
        /// </summary>
        /// <param name="availableWindows">The available windows.</param>
        public WinChooseWindow(IEnumerable<string> availableWindows) 
            : this() {
            windowChooser.AvailableWindows = availableWindows;
        }

        /// <summary>
        /// Checks a Window has been selected.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
        private void btnOk_Click(object sender, RoutedEventArgs e) {
            if(string.IsNullOrEmpty(SelectedWindow)) {
                DialogBox.ShowAlert(this, I18nUtils.GetString("Errors", "TargetWindowRequired"), I18nUtils.GetString("Errors", "Error"));
            } else {
                this.DialogResult = true;
            }
        }
    }
}
